"""
---------------------------------------------------------------------
- File: schemas.py
- Date: 2025/8/8
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description:
---------------------------------------------------------------------
"""

from datetime import datetime

# pydantic
from pydantic import BaseModel, field_serializer, computed_field

from app.common.app_utils import ToCamelBaseModel

class Token(BaseModel):
    """token"""

    access_token: str
    token_type: str

class UserNo(BaseModel):
    """用户id"""
    user_no: str

class TokenOut(Token):
    """TokenOut 符合swagger UI"""

    code: str = ("0000",)
    msg: str = "请求成功"
    data: Token


class TokenData(BaseModel):
    user_name: str | None = None


class UserOut(ToCamelBaseModel):
    user_no: str
    user_name: str
    nick_name: str
    user_gender: str
    user_email: str
    user_phone: str
    status: bool
    create_time: datetime
    update_time: datetime

    # 字段序列化
    @field_serializer("create_time", "update_time")
    def serializer_time(self, val: datetime | None, _info):
        return val.strftime("%Y-%m-%d %H:%M:%S") if val else None

    # 计算字段装饰器
    @computed_field
    def info(self) -> str:
        return f"{self.nick_name}{self.user_phone}"




class UserInDB(UserOut):
    hashed_password: str
